import Config from '../model/api/Config.js'

import { createRequire } from "module"
const require = createRequire(import.meta.url)
var mysql = require('mysql');
let databaseConfigData = Config.getConfig("database", "database");
const db = mysql.createPool({
    host: databaseConfigData.Database.host,
    user: databaseConfigData.Database.username,
    password: databaseConfigData.Database.password,
    database: 'xinghandatabase'
})

export async function sql_run(query) {
    return new Promise((resolve, reject) => {
        db.query(query, (err, result) => {
            if (err) {
                reject(err)
            }
            resolve(result)
        });
    });
}